package com.mentaleye.dal.dao.mybatis;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mentaleye.dal.dao.TeacherDao;
import com.mentaleye.dal.model.Teacher;
import com.mentaleye.dal.model.TeacherExample;
import com.mentaleye.dal.service.TeacherMapper;
@Repository
public class TeacherDaoImpl extends BaseDao implements TeacherDao {
@Autowired
	private TeacherMapper teacherMapper;
	@Override
	public boolean addTeacher(Teacher teacher) {
		/**
		 * 添加教师时，获取当前时间
		 * getResultByInt 写一个转换方法，将int类型转换成一个boolean类型
		 */
		teacher.setCreateTime(new Date());
		teacher.setModifyTime(new Date());
		return getResultByInt(teacherMapper.insertSelective(teacher));
	}

	@Override
	public boolean updateTeacher(Teacher teacher) {
		teacher.setModifyTime(new Date());
		return getResultByInt(teacherMapper.updateByPrimaryKeySelective(teacher));
	}

	@Override
	public boolean deleteTeacher(List<Integer> ids) {
		/**
		 * TeacherExample 中有createCriteria()方法，其下有很多逻辑方法。
		 */
		TeacherExample teacherExample = new TeacherExample();
		teacherExample.createCriteria().andTeacherNoIn(ids);
		return getResultByInt(teacherMapper.deleteByExample(teacherExample));
	}

	@Override
	public List<Teacher> queryTeacherList(TeacherExample teacherExample) {
		return teacherMapper.selectByExample(teacherExample);
	}

	@Override
	public List<Teacher> queryTeacher(Map<String, Object> map) {
		return teacherMapper.selectByMap(map);
	}
	
	@Override
	public List<Teacher> queryTeacherByDept(Map<String, Object> map) {
		return teacherMapper.selectByDept(map);
	}

	@Override
	public Teacher queryTeacherByNo(Integer teacherNo) {
		return teacherMapper.selectByPrimaryKey(teacherNo);
	}

	@Override
	public boolean updateTeacherStatus(List<Integer> ids, Teacher teacher) {
		TeacherExample teacherExample = new TeacherExample();
		teacherExample.createCriteria().andTeacherNoIn(ids);
		return getResultByInt(teacherMapper.updateByExampleSelective(teacher, teacherExample));
	}

	@Override
	public List<Teacher> queryTeacherByIds(List<Integer> ids) {
		TeacherExample  teacherExample = new TeacherExample();
		teacherExample.createCriteria().andTeacherNoIn(ids);
		return teacherMapper.selectByExample(teacherExample);
	}

	@Override
	public List<Teacher> queryTeacherByNotOaClass(Map<String, Object> map){
		return teacherMapper.selectTeacherByNotOaClass(map);
	}
	
	@Override
	public List<Teacher> queryTeacherByNotInIds(List<Integer> ids) {
		TeacherExample teacherExample = new TeacherExample();
		teacherExample.createCriteria().andTeacherNoNotIn(ids);
		return teacherMapper.selectByExample(teacherExample);
	}
	
	@Override
	public List<Teacher> queryTeacher(){
		return teacherMapper.selectTeacher();
	}

	@Override
	public List<Teacher> queryRoleTeacher(Map<String, Object> map) {
		return teacherMapper.selectTeacherByMap(map);
	}

	@Override
	public List<Teacher> queryAllTeacherByMap(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleNo", id);
		return teacherMapper.selectAllTeacherByMap(map);
	}

	@Override
	public List<Teacher> queryAllTeacherNotDel() {
		return teacherMapper.selectAllNoDel();
	}

}
